Skip to content

features: speed up large feature responses by removing event-buffer auto boxing#534

Merged
azahnen merged 2 commits into
masterfrom
opt-event-buffer
Jun 22, 2026
Merged

features: speed up large feature responses by removing event-buffer auto boxing#534
azahnen merged 2 commits into
masterfrom
opt-event-buffer

Conversation

@cportele

Copy link
Copy Markdown
Contributor

FeatureEventBuffer tracked per-position buffer offsets and lengths in a Vector<Integer>. Every offset update in plus()/increase() boxed and unboxed an Integer and took the Vector's monitor, and plus() does this in a loop over all following positions for every token appended. On wide features and large result sets this dominated CPU.

Store the offsets in a primitive int[] of the same fixed size instead: plus() now does plain int[] arithmetic, start()/length() read by index, and reset() uses Arrays.fill. No behavioral change; the feature-pipeline tests pass unchanged.

Profiling a large response: Integer.valueOf dropped from ~15% of CPU to 0, the buffer's share fell from ~35% to ~14%, streaming throughput rose ~40%, and wall-clock dropped ~30%.

…utoboxing

FeatureEventBuffer tracked per-position buffer offsets and lengths in a
Vector<Integer>. Every offset update in plus()/increase() boxed and unboxed
an Integer and took the Vector's monitor, and plus() does this in a loop over
all following positions for every token appended. On wide features and large
result sets this dominated CPU.

Store the offsets in a primitive int[] of the same fixed size instead:
plus() now does plain int[] arithmetic, start()/length() read by index, and
reset() uses Arrays.fill. No behavioral change; the feature-pipeline tests
pass unchanged.

Profiling a large response: Integer.valueOf dropped from ~15% of CPU to 0,
the buffer's share fell from ~35% to ~14%, streaming throughput rose ~40%,
and wall-clock for large areas dropped ~30%.
@azahnen azahnen enabled auto-merge (squash) June 22, 2026 07:58
@azahnen azahnen merged commit b9e9a03 into master Jun 22, 2026
3 checks passed
@azahnen azahnen deleted the opt-event-buffer branch June 22, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants